package com.ocom.payconfig.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ocom.common.entity.payconfig.EntityFoodstuffPurchase;
import com.ocom.common.request.payconfig.food.GetFoodPurchaseListRequest;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface IDaoFoodstuffPurchase extends BaseMapper<EntityFoodstuffPurchase> {

    @Select({"<script>",
            "select R.* , M.merch_name , P.staff_name , F.foodstuff_name  \n" +
                    "  from  foodstuff_purchase as R \n" +
                    "left join foodstuff_info as F  on F.foodstuff_id = R.foodstuff_id \n" +
                    "left join xf_merchant_info as M  on M.merch_id = R.merch_id \n" +
                    "left join rest_staff as P   on P.staff_id = R.rest_staff_id \n" +
                    "where R.com_id = #{request.comId} " +
                    "and  R.purchase_time <![CDATA[ >= ]]> #{request.beginDate}  and  R.purchase_time <![CDATA[ <= ]]> #{request.endDate} \n" +
                    "<when test=\"request.merchId!=null and request.merchId == 0\" > "+
                    "AND R.merch_id = #{request.merchId} \n" +
                    "</when> " +
                    "<when test=\"request.staffId!=null and request.staffId > 0\" > "+
                    "AND R.rest_staff_id = #{request.staffId} \n" +
                    "</when> " +
                    "<when test=\"request.foodstuffId!=null and request.foodstuffId > 0\" > "+
                    "AND R.foodstuff_id = #{request.foodstuffId} \n" +
                    "</when> " +
                    "  order by purchase_time " +
                    "</script>"})
    List<EntityFoodstuffPurchase> getList(@Param("request") GetFoodPurchaseListRequest request);

}
